// composables/useUser.js
import { ref, computed } from 'vue'
import { useUserStore } from '@/stores/user'

export function useUser() {
  const userStore = useUserStore()
  
  // 岗位信息计算属性
  const job = computed(() => userStore.userInfo?.job || '')
  
  // 用户名计算属性
  const username = computed(() => userStore.userInfo?.username || '')
	
	//用户id
  const userId = computed(() => userStore.userInfo?.id || '')
  
  // 判断用户角色等方法
  const isManager = computed(() => job.value === 'manager')
  const isDriver = computed(() => job.value === 'driver')
  
  return {
    job,
    username,
		userId,
    isManager,
    isDriver,
    userInfo: userStore.userInfo,
    setUserInfo: userStore.setUserInfo,
    clearUserInfo: userStore.clearUserInfo
  }
}